package com.mq.dialogdemo.dialogfragment;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.mq.dialogdemo.R;

public class DialogFragmentActivity extends AppCompatActivity implements MyDialogFragment.MyDialogListener {
    private static final String TAG = DialogFragmentActivity.class.getSimpleName();

    private TextView textView;

    private MyDialogFragment myDialogFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog_fragment);

        textView = (TextView) findViewById(R.id.text);

        myDialogFragment = new MyDialogFragment();
        myDialogFragment.show(getSupportFragmentManager(), "myDialogFragment");

//        myDialogFragment.setCancelable(false);

        Log.e(TAG, "onCreate: "+myDialogFragment.isCancelable());
    }

    @Override
    public void onDialogClick(String content, int type) {
        if (type == 1) {
            textView.setText("user: " + content);
        } else {
            textView.setText("password: " + content);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        myDialogFragment.dismiss();
    }
}
